/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cryptography;

import java.io.*;
import java.math.BigInteger;
import javax.swing.JFileChooser;

/**
 *
 * @author Mouchicc & Mavs
 * @version 1.0
 */
public class Encryption extends javax.swing.JFrame {

    /**
     * Creates new form Encryption
     */
    public Encryption() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fcCaesar = new javax.swing.JFileChooser();
        fcVigenere = new javax.swing.JFileChooser();
        fcRSA = new javax.swing.JFileChooser();
        fcArcanum = new javax.swing.JFileChooser();
        jFileChooser5 = new javax.swing.JFileChooser();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        Home = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        Caesar = new javax.swing.JPanel();
        caesarTitel = new javax.swing.JLabel();
        caesarOut = new javax.swing.JLabel();
        caesarFileLabel = new javax.swing.JLabel();
        caesarFilePath = new javax.swing.JTextField();
        caesarEncrypt = new javax.swing.JButton();
        caesarDecrypt = new javax.swing.JButton();
        caesarPass = new javax.swing.JTextField();
        caesarBrowse = new javax.swing.JButton();
        Vigenere = new javax.swing.JPanel();
        vigenereTitel = new javax.swing.JLabel();
        vigenereOut = new javax.swing.JLabel();
        vigenereFileLabel = new javax.swing.JLabel();
        vigenereFilePath = new javax.swing.JTextField();
        vigenereEncrypt = new javax.swing.JButton();
        vigenereDecrypt = new javax.swing.JButton();
        vigenerePass = new javax.swing.JTextField();
        vigenereBrowse = new javax.swing.JButton();
        RSA = new javax.swing.JPanel();
        caesarTitel1 = new javax.swing.JLabel();
        RSAOut = new javax.swing.JLabel();
        RSAFileLabel = new javax.swing.JLabel();
        RSAFilePath = new javax.swing.JTextField();
        RSAEncrypt = new javax.swing.JButton();
        RSADecrypt = new javax.swing.JButton();
        RSAp = new javax.swing.JTextField();
        RSABrowse = new javax.swing.JButton();
        RSAq = new javax.swing.JTextField();
        RSApublickey = new javax.swing.JTextField();
        RSAmod = new javax.swing.JTextField();
        RSAprivatekey = new javax.swing.JTextField();
        Arcanum = new javax.swing.JPanel();
        arcanumTitel = new javax.swing.JLabel();
        arcanumOut = new javax.swing.JLabel();
        arcanumFileLabel = new javax.swing.JLabel();
        arcanumFilePath = new javax.swing.JTextField();
        arcanumEncrypt = new javax.swing.JButton();
        arcanumDecrypt = new javax.swing.JButton();
        arcanumPass = new javax.swing.JTextField();
        arcanumBrowse = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cryptography - by Mouchicc & Mavs");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jTextField1.setText("Main information here...");

        org.jdesktop.layout.GroupLayout HomeLayout = new org.jdesktop.layout.GroupLayout(Home);
        Home.setLayout(HomeLayout);
        HomeLayout.setHorizontalGroup(
            HomeLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(HomeLayout.createSequentialGroup()
                .addContainerGap()
                .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 337, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(227, Short.MAX_VALUE))
        );
        HomeLayout.setVerticalGroup(
            HomeLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(HomeLayout.createSequentialGroup()
                .addContainerGap()
                .add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 293, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Home", Home);

        caesarTitel.setFont(new java.awt.Font("TI-83p Mini Sans", 3, 36)); // NOI18N
        caesarTitel.setText("           Caesar ");

        caesarFileLabel.setText("Filepath:");

        caesarFilePath.setText("Path..");

        caesarEncrypt.setText("Encrypt");
        caesarEncrypt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                caesarEncryptActionPerformed(evt);
            }
        });

        caesarDecrypt.setText("Decrypt");
        caesarDecrypt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                caesarDecryptActionPerformed(evt);
            }
        });

        caesarPass.setText("Password");

        caesarBrowse.setText("Browse..");
        caesarBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                caesarBrowseActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout CaesarLayout = new org.jdesktop.layout.GroupLayout(Caesar);
        Caesar.setLayout(CaesarLayout);
        CaesarLayout.setHorizontalGroup(
            CaesarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(CaesarLayout.createSequentialGroup()
                .add(CaesarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(CaesarLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(caesarFileLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(CaesarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(caesarTitel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 358, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(CaesarLayout.createSequentialGroup()
                                .add(CaesarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(caesarFilePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 352, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(CaesarLayout.createSequentialGroup()
                                        .add(caesarPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 104, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(12, 12, 12)
                                        .add(caesarEncrypt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 116, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(caesarDecrypt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(caesarBrowse, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(CaesarLayout.createSequentialGroup()
                        .add(35, 35, 35)
                        .add(caesarOut, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 465, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(48, Short.MAX_VALUE))
        );
        CaesarLayout.setVerticalGroup(
            CaesarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(CaesarLayout.createSequentialGroup()
                .add(caesarTitel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 57, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(14, 14, 14)
                .add(CaesarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(CaesarLayout.createSequentialGroup()
                        .add(CaesarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(caesarFileLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(caesarFilePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(CaesarLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(caesarDecrypt)
                            .add(caesarPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(caesarEncrypt)))
                    .add(CaesarLayout.createSequentialGroup()
                        .add(1, 1, 1)
                        .add(caesarBrowse)))
                .add(71, 71, 71)
                .add(caesarOut, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
                .add(34, 34, 34))
        );

        jTabbedPane1.addTab("Caesar", Caesar);

        vigenereTitel.setFont(new java.awt.Font("TI-83p Mini Sans", 3, 36)); // NOI18N
        vigenereTitel.setText("          Vigenère ");

        vigenereFileLabel.setText("Filepath:");

        vigenereFilePath.setText("Path..");

        vigenereEncrypt.setText("Encrypt");
        vigenereEncrypt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vigenereEncryptActionPerformed(evt);
            }
        });

        vigenereDecrypt.setText("Decrypt");
        vigenereDecrypt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vigenereDecryptActionPerformed(evt);
            }
        });

        vigenerePass.setText("Password");

        vigenereBrowse.setText("Browse..");
        vigenereBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vigenereBrowseActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout VigenereLayout = new org.jdesktop.layout.GroupLayout(Vigenere);
        Vigenere.setLayout(VigenereLayout);
        VigenereLayout.setHorizontalGroup(
            VigenereLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(VigenereLayout.createSequentialGroup()
                .add(VigenereLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(VigenereLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(vigenereFileLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(VigenereLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(vigenereTitel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 358, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(VigenereLayout.createSequentialGroup()
                                .add(VigenereLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(vigenereFilePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 352, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(VigenereLayout.createSequentialGroup()
                                        .add(vigenerePass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 104, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(12, 12, 12)
                                        .add(vigenereEncrypt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 116, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(vigenereDecrypt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(vigenereBrowse, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(VigenereLayout.createSequentialGroup()
                        .add(35, 35, 35)
                        .add(vigenereOut, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 465, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(48, Short.MAX_VALUE))
        );
        VigenereLayout.setVerticalGroup(
            VigenereLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(VigenereLayout.createSequentialGroup()
                .add(vigenereTitel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 57, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(14, 14, 14)
                .add(VigenereLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(VigenereLayout.createSequentialGroup()
                        .add(VigenereLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(vigenereFileLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(vigenereFilePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(VigenereLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(vigenereDecrypt)
                            .add(vigenerePass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(vigenereEncrypt)))
                    .add(VigenereLayout.createSequentialGroup()
                        .add(1, 1, 1)
                        .add(vigenereBrowse)))
                .add(71, 71, 71)
                .add(vigenereOut, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
                .add(34, 34, 34))
        );

        jTabbedPane1.addTab("Vigenère", Vigenere);

        caesarTitel1.setFont(new java.awt.Font("TI-83p Mini Sans", 3, 36)); // NOI18N
        caesarTitel1.setText("            RSA");

        RSAFileLabel.setText("Filepath:");

        RSAFilePath.setText("Path..");

        RSAEncrypt.setText("Encrypt");
        RSAEncrypt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RSAEncryptActionPerformed(evt);
            }
        });

        RSADecrypt.setText("Decrypt");
        RSADecrypt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RSADecryptActionPerformed(evt);
            }
        });

        RSAp.setText("Insert p..");

        RSABrowse.setText("Browse..");
        RSABrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RSABrowseActionPerformed(evt);
            }
        });

        RSAq.setText("Insert q..");

        RSApublickey.setText("Public key..");

        RSAmod.setText("Modulus");

        RSAprivatekey.setText("Private key..");

        org.jdesktop.layout.GroupLayout RSALayout = new org.jdesktop.layout.GroupLayout(RSA);
        RSA.setLayout(RSALayout);
        RSALayout.setHorizontalGroup(
            RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(RSALayout.createSequentialGroup()
                .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(RSALayout.createSequentialGroup()
                        .addContainerGap()
                        .add(RSAFileLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(caesarTitel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 358, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(RSALayout.createSequentialGroup()
                                .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(RSALayout.createSequentialGroup()
                                        .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                            .add(RSAmod)
                                            .add(RSAp, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                            .add(RSAprivatekey)
                                            .add(RSAq))
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, RSALayout.createSequentialGroup()
                                                .add(RSApublickey, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(RSAEncrypt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 103, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, RSADecrypt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 105, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                    .add(RSAFilePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 372, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(RSABrowse, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(RSALayout.createSequentialGroup()
                        .add(35, 35, 35)
                        .add(RSAOut, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 465, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        RSALayout.setVerticalGroup(
            RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(RSALayout.createSequentialGroup()
                .add(caesarTitel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 57, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(14, 14, 14)
                .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(RSALayout.createSequentialGroup()
                        .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(RSAFileLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(RSAFilePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(RSAp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(RSAEncrypt)
                            .add(RSAq, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(RSApublickey, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(RSALayout.createSequentialGroup()
                        .add(1, 1, 1)
                        .add(RSABrowse)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(RSADecrypt)
                    .add(RSALayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(RSAmod, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(RSAprivatekey, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(36, 36, 36)
                .add(RSAOut, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
                .add(34, 34, 34))
        );

        jTabbedPane1.addTab("RSA", RSA);

        arcanumTitel.setFont(new java.awt.Font("TI-83p Mini Sans", 3, 36)); // NOI18N
        arcanumTitel.setText("           Arcanum ");

        arcanumFileLabel.setText("Filepath:");

        arcanumFilePath.setText("Path..");

        arcanumEncrypt.setText("Encrypt");
        arcanumEncrypt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                arcanumEncryptActionPerformed(evt);
            }
        });

        arcanumDecrypt.setText("Decrypt");
        arcanumDecrypt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                arcanumDecryptActionPerformed(evt);
            }
        });

        arcanumPass.setText("Password");

        arcanumBrowse.setText("Browse..");
        arcanumBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                arcanumBrowseActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout ArcanumLayout = new org.jdesktop.layout.GroupLayout(Arcanum);
        Arcanum.setLayout(ArcanumLayout);
        ArcanumLayout.setHorizontalGroup(
            ArcanumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(ArcanumLayout.createSequentialGroup()
                .add(ArcanumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(ArcanumLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(arcanumFileLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(ArcanumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(arcanumTitel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 358, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(ArcanumLayout.createSequentialGroup()
                                .add(ArcanumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(arcanumFilePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 352, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(ArcanumLayout.createSequentialGroup()
                                        .add(arcanumPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 104, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(12, 12, 12)
                                        .add(arcanumEncrypt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 116, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(arcanumDecrypt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(arcanumBrowse, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(ArcanumLayout.createSequentialGroup()
                        .add(35, 35, 35)
                        .add(arcanumOut, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 465, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(48, Short.MAX_VALUE))
        );
        ArcanumLayout.setVerticalGroup(
            ArcanumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(ArcanumLayout.createSequentialGroup()
                .add(arcanumTitel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 57, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(14, 14, 14)
                .add(ArcanumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(ArcanumLayout.createSequentialGroup()
                        .add(ArcanumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(arcanumFileLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(arcanumFilePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(ArcanumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(arcanumDecrypt)
                            .add(arcanumPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(arcanumEncrypt)))
                    .add(ArcanumLayout.createSequentialGroup()
                        .add(1, 1, 1)
                        .add(arcanumBrowse)))
                .add(71, 71, 71)
                .add(arcanumOut, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
                .add(34, 34, 34))
        );

        jTabbedPane1.addTab("Arcanum", Arcanum);

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(209, 209, 209)
                .add(jButton1)
                .addContainerGap(264, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(92, 92, 92)
                .add(jButton1)
                .addContainerGap(184, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("tab6", jPanel2);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-603)/2, (screenSize.height-385)/2, 603, 385);
    }// </editor-fold>//GEN-END:initComponents

    private void caesarBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caesarBrowseActionPerformed
        JFileChooser fc = fcCaesar;

        if (evt.getSource() == caesarBrowse) {
            ExtensionFileFilter jarFilter = new ExtensionFileFilter(
                    "txt", ".txt Files");
            fc.addChoosableFileFilter(jarFilter);
            int returnVal = fc.showOpenDialog(Encryption.this);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                caesarFilePath.setText("" + file);
            } else {
                caesarFilePath.setText("Open command cancelled by user.");
            }
        }
    }//GEN-LAST:event_caesarBrowseActionPerformed

    private void caesarEncryptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caesarEncryptActionPerformed
        String pass = caesarPass.getText();
        int p = Methods.passToInt(pass);

        String path = caesarFilePath.getText();
        String outputPath = path.substring(0, path.length() - 4) + "_caesar_enc" + path.substring(path.length() - 4, path.length());


        if (evt.getSource() == caesarEncrypt) {
            String enc = readFile(caesarFilePath.getText());

            Caesar encrypt = new Caesar(enc, p);
            String encrypted = encrypt.encrypt();
            writeFile(encrypted, outputPath);

            boolean exists = (new File(outputPath)).exists();
            if (exists) {
                caesarOut.setText("Your encrypted file is successfully created.");
            } else {
                caesarOut.setText("There went something wrong, file is not created!");
            }
        }
    }//GEN-LAST:event_caesarEncryptActionPerformed

    private void caesarDecryptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caesarDecryptActionPerformed
        String pass = caesarPass.getText();
        int p = Methods.passToInt(pass);

        String path = caesarFilePath.getText();
        String outputPath = path.substring(0, path.length() - 8) + "_dec" + path.substring(path.length() - 4, path.length());

        if (evt.getSource() == caesarDecrypt) {
            String dec = readFile(caesarFilePath.getText());

            Caesar decrypt = new Caesar(dec, p);
            String decrypted = decrypt.decrypt();
            writeFile(decrypted, outputPath);

            boolean exists = (new File(outputPath)).exists();
            if (exists) {
                caesarOut.setText("Your decrypted file is successfully created.");
            } else {
                caesarOut.setText("There went something wrong, file is not created!");
            }
        }
    }//GEN-LAST:event_caesarDecryptActionPerformed

    private void vigenereEncryptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vigenereEncryptActionPerformed
        String pass = vigenerePass.getText();

        String path = vigenereFilePath.getText();
        String outputPath = path.substring(0, path.length() - 4) + "_vigenere_enc" + path.substring(path.length() - 4, path.length());


        if (evt.getSource() == vigenereEncrypt) {
            String enc = readFile(vigenereFilePath.getText());
            Vigenere encrypt = new Vigenere(enc, pass);
            String encrypted = encrypt.encrypt();
            writeFile(encrypted, outputPath);

            boolean exists = (new File(outputPath)).exists();
            if (exists) {
                vigenereOut.setText("Your encrypted file is successfully created.");
            } else {
                vigenereOut.setText("There went something wrong, file is not created!");
            }
        }
    }//GEN-LAST:event_vigenereEncryptActionPerformed

    private void vigenereDecryptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vigenereDecryptActionPerformed
        String pass = vigenerePass.getText();
        int p = Methods.passToInt(pass);

        String path = vigenereFilePath.getText();
        String outputPath = path.substring(0, path.length() - 8) + "_vigenere_dec" + path.substring(path.length() - 4, path.length());

        if (evt.getSource() == vigenereDecrypt) {
            String dec_1 = readFile(vigenereFilePath.getText());
            String dec_2 = dec_1.replaceAll("\\s+", "(").replaceAll("\\(", " ");

            Vigenere decrypt = new Vigenere(dec_1, pass);
            String decrypted = decrypt.decrypt();
            writeFile(decrypted, outputPath);

            boolean exists = (new File(outputPath)).exists();
            if (exists) {
                vigenereOut.setText("Your decrypted file is successfully created.");
            } else {
                vigenereOut.setText("There went something wrong, file is not created!");
            }
        }
    }//GEN-LAST:event_vigenereDecryptActionPerformed

    private void vigenereBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vigenereBrowseActionPerformed
        JFileChooser fc = fcVigenere;

        if (evt.getSource() == vigenereBrowse) {
            ExtensionFileFilter jarFilter = new ExtensionFileFilter(
                    "txt", ".txt Files");
            fc.addChoosableFileFilter(jarFilter);
            int returnVal = fc.showOpenDialog(Encryption.this);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                vigenereFilePath.setText("" + file);
            } else {
                vigenereFilePath.setText("Open command cancelled by user.");
            }
        }
    }//GEN-LAST:event_vigenereBrowseActionPerformed

    private void RSAEncryptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RSAEncryptActionPerformed
        BigInteger p = new BigInteger(RSAp.getText());
        BigInteger q = new BigInteger(RSAq.getText());
        BigInteger publickey = new BigInteger(RSApublickey.getText());

        String path = RSAFilePath.getText();
        String outputPath = path.substring(0, path.length() - 4) + "_rsa_enc" + path.substring(path.length() - 4, path.length());

        if (evt.getSource() == RSAEncrypt) {
            String s = readFile(RSAFilePath.getText());

            RSA enc = new RSA(p, q, publickey);
            BigInteger[] cyphertext = enc.encode(s);

            writeFile(bitoString(cyphertext), outputPath);

            boolean exists = (new File(outputPath)).exists();
            if (exists) {
                RSAOut.setText("Your encrypted file is successfully created.");
            } else {
                RSAOut.setText("There went something wrong, file is not created!");
            }
        }
    }//GEN-LAST:event_RSAEncryptActionPerformed

    private void RSADecryptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RSADecryptActionPerformed
        BigInteger mod = new BigInteger(RSAmod.getText());
        BigInteger privatekey = new BigInteger(RSAprivatekey.getText());

        String path = RSAFilePath.getText();
        String outputPath = path.substring(0, path.length() - 8) + "_rsa_dec" + path.substring(path.length() - 4, path.length());

        if (evt.getSource() == RSADecrypt) {
            String s = readFile(RSAFilePath.getText());

            RSA dec = new RSA(mod, privatekey);
            String plaintext = dec.decode(stringToBI(s));
            writeFile(plaintext, outputPath);

            boolean exists = (new File(outputPath)).exists();
            if (exists) {
                RSAOut.setText("Your decrypted file is successfully created.");
            } else {
                RSAOut.setText("There went something wrong, file is not created!");
            }
        }
    }//GEN-LAST:event_RSADecryptActionPerformed

    public String bitoString(BigInteger[] bis) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < bis.length; i++) {
            sb.append(bis[i]).append(" ");
        }
        return sb.toString();
    }

    public BigInteger[] stringToBI(String s) {
        String[] splitted = s.split(" ");
        BigInteger[] out = new BigInteger[splitted.length];
        for (int i = 0; i < splitted.length; i++) {
            out[i] = new BigInteger(splitted[i]);
        }
        return out;
    }

    private void RSABrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RSABrowseActionPerformed
        JFileChooser fc = fcRSA;

        if (evt.getSource() == RSABrowse) {
            ExtensionFileFilter jarFilter = new ExtensionFileFilter(
                    "txt", ".txt Files");
            fc.addChoosableFileFilter(jarFilter);
            int returnVal = fc.showOpenDialog(Encryption.this);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                RSAFilePath.setText("" + file);
            } else {
                RSAFilePath.setText("Open command cancelled by user.");
            }
        }
    }//GEN-LAST:event_RSABrowseActionPerformed

    private void arcanumEncryptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_arcanumEncryptActionPerformed
        String pass = arcanumPass.getText();

        String path = arcanumFilePath.getText();

        if (evt.getSource() == arcanumEncrypt) {
            Arcanum enc = new Arcanum(path, pass);
            enc.encrypt();

            boolean exists = (new File(enc.OUT)).exists();
            if (exists) {
                arcanumOut.setText("Your encrypted file is successfully created.");
            } else {
                arcanumOut.setText("There went something wrong, file is not created!");
            }
        }
    }//GEN-LAST:event_arcanumEncryptActionPerformed

    private void arcanumDecryptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_arcanumDecryptActionPerformed
        String pass = arcanumPass.getText();

        try {
            String path = arcanumFilePath.getText(); // /Users/Najima/Mourad PWS/pok112_arcanum_enc.png            

            if (evt.getSource() == arcanumDecrypt) {
                Arcanum dec = new Arcanum(path, pass);
                dec.decrypt();

                boolean exists = (new File(dec.OUT)).exists();
                if (exists) {
                    arcanumOut.setText("Your decrypted file is successfully created.");
                } else {
                    arcanumOut.setText("There went something wrong, file is not created!");
                }
            }
        } catch (Exception e) {
        }


    }//GEN-LAST:event_arcanumDecryptActionPerformed

    private void arcanumBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_arcanumBrowseActionPerformed
        JFileChooser fc = fcArcanum;

        if (evt.getSource() == arcanumBrowse) {
            //ExtensionFileFilter jarFilter = new ExtensionFileFilter(
            //        "png", ".png Files");
            //fc.addChoosableFileFilter(jarFilter);
            int returnVal = fc.showOpenDialog(Encryption.this);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                arcanumFilePath.setText("" + file);
            } else {
                arcanumFilePath.setText("Open command cancelled by user.");
            }
        }
    }//GEN-LAST:event_arcanumBrowseActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Caesar_About.main(new String[]{});
    }//GEN-LAST:event_jButton1ActionPerformed

    public static String readFile(String path) {
        String s = "";
        StringBuilder contents = new StringBuilder();
        File file = new File(path);
        FileInputStream fis = null;
        BufferedInputStream bis = null;
        DataInputStream dis = null;

        try {
            fis = new FileInputStream(file);
            bis = new BufferedInputStream(fis);
            dis = new DataInputStream(bis);

            while (dis.available() != 0) {
                s = dis.readLine();
                contents.append(s);
                contents.append(System.getProperty("line.separator"));
            }
            contents.deleteCharAt(contents.length() - 1);

            fis.close();
            bis.close();
            dis.close();

        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }
        return contents.toString();
    }

    /**
     * Prints some data to a file
     */
    public static void writeFile(String s, String filename) {

        BufferedOutputStream bufferedOutput = null;

        try {

            bufferedOutput = new BufferedOutputStream(new FileOutputStream(filename));
            bufferedOutput.write(s.getBytes());

        } catch (FileNotFoundException ex) {
        } catch (IOException ex) {
        } finally {

            try {
                if (bufferedOutput != null) {
                    bufferedOutput.flush();
                    bufferedOutput.close();
                }
            } catch (IOException ex) {
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Encryption().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel Arcanum;
    private javax.swing.JPanel Caesar;
    private javax.swing.JPanel Home;
    private javax.swing.JPanel RSA;
    private javax.swing.JButton RSABrowse;
    private javax.swing.JButton RSADecrypt;
    private javax.swing.JButton RSAEncrypt;
    private javax.swing.JLabel RSAFileLabel;
    private javax.swing.JTextField RSAFilePath;
    private javax.swing.JLabel RSAOut;
    private javax.swing.JTextField RSAmod;
    private javax.swing.JTextField RSAp;
    private javax.swing.JTextField RSAprivatekey;
    private javax.swing.JTextField RSApublickey;
    private javax.swing.JTextField RSAq;
    private javax.swing.JPanel Vigenere;
    private javax.swing.JButton arcanumBrowse;
    private javax.swing.JButton arcanumDecrypt;
    private javax.swing.JButton arcanumEncrypt;
    private javax.swing.JLabel arcanumFileLabel;
    private javax.swing.JTextField arcanumFilePath;
    private javax.swing.JLabel arcanumOut;
    private javax.swing.JTextField arcanumPass;
    private javax.swing.JLabel arcanumTitel;
    private javax.swing.JButton caesarBrowse;
    private javax.swing.JButton caesarDecrypt;
    private javax.swing.JButton caesarEncrypt;
    private javax.swing.JLabel caesarFileLabel;
    private javax.swing.JTextField caesarFilePath;
    private javax.swing.JLabel caesarOut;
    private javax.swing.JTextField caesarPass;
    private javax.swing.JLabel caesarTitel;
    private javax.swing.JLabel caesarTitel1;
    private javax.swing.JFileChooser fcArcanum;
    private javax.swing.JFileChooser fcCaesar;
    private javax.swing.JFileChooser fcRSA;
    private javax.swing.JFileChooser fcVigenere;
    private javax.swing.JButton jButton1;
    private javax.swing.JFileChooser jFileChooser5;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JButton vigenereBrowse;
    private javax.swing.JButton vigenereDecrypt;
    private javax.swing.JButton vigenereEncrypt;
    private javax.swing.JLabel vigenereFileLabel;
    private javax.swing.JTextField vigenereFilePath;
    private javax.swing.JLabel vigenereOut;
    private javax.swing.JTextField vigenerePass;
    private javax.swing.JLabel vigenereTitel;
    // End of variables declaration//GEN-END:variables
}
